<!DOCTYPE html>
<html>
<head>
    <title>模具故障分类排列图</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak style="width: 100%;height:100%;margin: 20px">
    <Row :gutter="16" style="margin: 8px 0px 0px 1px">
        <div class="search-group">
            <i-col span="3">
                <i-select v-model="q.dept" placeholder="所属车间">
                    <i-option v-for="item in deptList" :value="item.deptId" :key="item.deptId">{{item.name}}
                    </i-option>
                </i-select>
            </i-col>
            <i-col span="4">
                <Date-picker type="daterange" v-model="q.month" placeholder="请选择查询时间段"></Date-picker>
            </i-col>
            <i-button @click="query">查询</i-button>
            <i-button @click="reloadSearch">重置</i-button>
        </div>
    </Row>
    <Row :gutter="16" style="margin-top: 15px">
        <div style="height: 85vh;width:12%;overflow:auto;float:left;">
            <p class="text-center" style="font-size: 15px;">模具类型</p>
            <div id="storeLayer">
                <ul id="typeTree" class="ztree"></ul>
            </div>
        </div>
        <div id="container" style="width: 75%;height:480px;overflow:auto;float:left;margin: 10px;padding: 20px;border: 1px solid #000"></div>
    </Row>
</div>
</div>
<script src="${rc.contextPath}/statics/plugins/echarts/echarts.min.js"></script>
<script>
    $(function () {
        // 加载铸造车间列表
        Ajax.request({
            url: "../sys/dept/getCJ",
            async: true,
            successCallback: function (res) {
                vm.deptList = res.deptList;
            }
        });
        vm.getTypeTree();
        vm.query();
    });
    // 模具分类树初始化
    var typeTree;
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "superType",
                rootPId: 0
            },
            key: {
                url: "nourl",
                name: "typeName" //name 与 typeName 绑定
            },
        },
        callback: {
            onClick: function () {
                var node = typeTree.getSelectedNodes();
                vm.q.mouldTypeId = node[0].id;
                vm.query();
            }

        }
    };

    var myChart;
    var vm = new Vue({
        el: '#rrapp',
        data: {
            deptList:[], // 车间列表
            q: {
                month: [], // 查询月份
                mouldTypeId: '', // 模具类别ID
                dept: '' // 所属车间
            },
            option: {
                title: {
                    text: '模具故障分类次数统计',
                    x: 'center',
                    y: 'top',
                    textAlign: 'left'
                },
                color:['#4472c4'],
                tooltip: {
                    trigger: 'axis',
                },
                toolbox: {
                    show: true,
                    feature: {
                        magicType: {show: true, type: ['line', 'bar']},
                        dataView: {show: true, readOnly: false},
                        saveAsImage: {show: true}
                    },
                    trigger: 'axis',
                    axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    },
                    formatter: function (params) {
                        var tar = params[1];
                        return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
                    }
                },
                grid:{
                    bottom:'15%'
                },
                xAxis: [{
                    type: 'category',
                    data: [],
                    axisLabel: { //坐标轴刻度标签的相关设置。
                        rotate: 50
                    },
                }],
                yAxis: [
                    {
                        type: 'value',
                        minInterval: 1
                    }
                ],
                series: [
                    {
                        name: '故障次数',
                        type: 'bar',
                        barWidth: '60%',
                        data: []
                    }
                ]
            }
        },
        methods: {
            reloadSearch: function () {
                this.q = {
                    month: [],
                    mouldTypeId : '',
                    dept: ''
                };
                // 取消选中
                typeTree.cancelSelectedNode();
                vm.query();
            },
            query: function () {
                var param = {};
                if (this.q.month && this.q.month.length == 2) {
                    if(this.q.month[0]){
                        param.startDate = dateToString(this.q.month[0]) + ' 0:00:00';
                    }
                    if(this.q.month[1]){
                        param.endDate = dateToString(this.q.month[1]) + ' 23:59:59';
                    }
                }
                if (this.q.mouldTypeId) {
                    param.mouldTypeId = this.q.mouldTypeId;
                }
                if (this.q.dept) {
                    param.dept = this.q.dept;
                }
                myChart.showLoading();
                Ajax.request({
                    url: "../mould/stat/faultClassifyTimes",
                    params: param,
                    type: "POST",
                    successCallback: function (res) {
                        myChart.hideLoading();
                        myChart.setOption({
                            xAxis: {
                                data: res.faultClassifyTimesStatData.devNames
                            },
                            series: {
                                data: res.faultClassifyTimesStatData.faultTimes
                            }
                        });
                    }
                });
            },
            getTypeTree: function () {
                //加载模具类型树
                Ajax.request({
                    url: "../moduletype/select",
                    async: true,
                    successCallback: function (r) {
                        typeTree = $.fn.zTree.init($("#typeTree"), setting, r.typeList);
                        typeTree.expandAll(true);
                    }
                });
            }
        },
        mounted: function () {
            // 初始化
            myChart = echarts.init(document.getElementById("container"));
            myChart.setOption(this.option, true);
            this.query();
        }
    });

</script>

</body>
</html>
